package com.lu.pojo.loop;

/**
 * @Author:luzhenfang
 * @Date:2020 3 20
 * @Desc: 该为 打印 输出类 共 10 个方法
 */


public class PrintGraph {
    // 打印矩形
    public void printRect(int width, int height) {
        for (int i = 0; i < height; i++) {
            for (int j = 0; j < width; j++) {
                System.out.print("*");
            }
            System.out.print("\n");
        }
    }

    // 打印直角三角形  或反转
    public void printTriangle(int deep, boolean isReverse) {
        if (isReverse) {
            for (int i = deep; i > 0; i--) {
                for (int j = i; j > 0; j--) {
                    System.out.print("*");
                }
                System.out.println();
            }
        } else {
            for (int i = 1; i <= deep; i++) {
                for (int j = 0; j < i; j++) {
                    System.out.print("*");
                }
                System.out.println();
            }
        }
    }

    public void printIsosceles(int deep) {
        for (int i = 1; i <= deep; i++) {//控制行数
            for (int k = 1; k <= deep - i; k++) {//控制空格的个数
                System.out.print(" ");
            }
            for (int j = 1; j <= 2 * i - 1; j++) {//控制打印的图形
                System.out.print("*");
            }
            System.out.println();//控制换行
        }

    }

    public void printParallelogram(int size) {
        for (int i = 0; i < size; i++) {//行
            for (int j = 0; j < size - i; j++) {
                System.out.print(" ");//空格
            }
            for (int j = 0; j < size * 2 - 1; j++) {//列
                System.out.print("*");

            }
            System.out.println();
        }

    }

    public void printDiamond(int size) {
        size /= 2;
        for (int i = 1; i <= size; i++) {
            for (int j = 1; j <= size - i; j++) {
                System.out.print(" ");
            }

            for (int k = 1; k <= 2 * i - 1; k++) {
                System.out.print('*');
            }
            System.out.println();
        }
        for (int i = 1; i <= size - 1; i++) {
            for (int j = 1; j <= i; j++) {
                System.out.print(" ");
            }

            for (int k = 2 * size - 3; k >= 2 * i - 1; k--) {
                System.out.print('*');
            }
            System.out.println();
        }
    }


    public void sumFor100Even() {
        int sum = 0;
        for (int i = 1; i <= 100; i++) {
            if (i % 2 == 0) {
                sum += i;
            }

        }
    }

    public void sumFor100() {
        int sum = 0;
        for (int i = 0; i < 100; i++) {
            sum += (i + 1);
        }
        System.out.println(sum);
    }


    public void sumWhile100() {
        int flag = 100;
        int sum = 0;
        while (flag > 0) {
            sum += flag;
            flag--;
        }
        System.out.println(sum);
    }

    public void sumWhile100Even() {
        int i = 100;
        int sum = 0;
        while (i > 0) {
            if (i % 2 == 0)
                sum += i;
            i--;
        }
        System.out.println(sum);
    }

    public void printPrime(int maxSize) {
        int i, j;
        for (i = 2; i <= maxSize; i++) {
            for (j = 2; j < i; j++) {
                if (i % j == 0)
                    break;
            }
            if (j >= i)
                System.out.print(i+" ");
        }
    }


}
